#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from dataclasses import dataclass
from typing import List, Optional, TYPE_CHECKING

if TYPE_CHECKING:
    from .models import VideoQuality

@dataclass
class VideoPart:
    """视频分P信息"""
    cid: str
    title: str
    video_url: str = ""
    audio_url: str = ""
    danmaku_url: str = ""
    subtitles: List = None
    qualities: List['VideoQuality'] = None

    def __post_init__(self):
        if self.subtitles is None:
            self.subtitles = []
        if self.qualities is None:
            self.qualities = []

    def __eq__(self, other):
        if not isinstance(other, VideoPart):
            return False
        return str(self.cid) == str(other.cid)

    def __hash__(self):
        return hash(str(self.cid))

@dataclass
class VideoQuality:
    """视频清晰度信息"""
    quality: str
    height: int
    width: int = 0
    url: str = ""

    def __eq__(self, other):
        if not isinstance(other, VideoQuality):
            return False
        return str(self.quality) == str(other.quality)

    def __hash__(self):
        return hash(str(self.quality))

@dataclass
class Subtitle:
    """字幕信息"""
    language: str
    url: str

@dataclass
class VideoInfo:
    """视频信息"""
    title: str
    author: str = ""
    cover: str = ""
    bvid: str = ""
    parts: List[VideoPart] = None
    qualities: List[VideoQuality] = None

    def __post_init__(self):
        if self.parts is None:
            self.parts = []
        if self.qualities is None:
            self.qualities = [] 